<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true">
				<el-form-item>
					<template>
						<el-select  @change="selectQueryPosition"
							v-model="selectPositionCode"
							clearable
							style="margin-left: 20px;"
							placeholder="请选择位置">
								<el-option 
									v-for="item in adPosition"
									:key="item.position"
									:label="item.positionName"
									:value="item.position">
								</el-option>
						</el-select>
					</template>

					<template>
						<el-select v-model="selectValid" placeholder="请选择是否有效" >
							<el-option
							clearable
							v-for="item in validoptions"
							:key="item.value"
							:label="item.label"
							:value="item.value">
							</el-option>
						</el-select>
					</template>

					<el-form-item >
					<div style="block">
						<span>开始时间</span>
						<el-date-picker
						v-model="selectBeginTime"
						type="date"
						placeholder="选择日期"
						format="yyyy 年 MM 月 dd 日"
						value-format="yyyy-MM-dd">
						</el-date-picker>
						~
						<el-date-picker
						v-model="selectEndTime"
						type="date"
						placeholder="选择日期"
						format="yyyy 年 MM 月 dd 日"
						value-format="yyyy-MM-dd">
						</el-date-picker>
					</div>
					</el-form-item>
					
					<div style="margin-top:10px">
						<div style="margin-left:10px;width:200px;display:inline-block;padding-right:10px;padding-left:10px;">
							<el-input v-model="inputAdTitle" width="200" placeholder="广告标题"></el-input>
						</div>
						<el-button type="primary" @click="getList" style="margin-left:20px">查询</el-button>
						<el-button type="primary" @click="handleAdd" style="margin-left:10px">新增</el-button>
					</div>
				</el-form-item>
			</el-form>
		</el-col>
		<!--列表-->
		<el-table :data="tagsList" highlight-current-row v-loading="listLoading" @selection-change="selsChange" style="width: 100%;">
			<el-table-column prop="positionName" label="广告位置" width="200" sortable/>
			<el-table-column prop="positionCode" label="广告编码" width="200" sortable/>
			<el-table-column prop="adTitle" label="广告标题"  width="170" sortable/>
			<el-table-column prop="beginTime" label="开始时间" width="170" sortable>
			</el-table-column>
			<el-table-column prop="endTime" label="结束时间" width="170" sortable>
				<template scope="scope">
					<div>
						<div v-if="compareNow(scope.row.endTime)">
							<p>{{scope.row.endTime}}</p>
						</div>
						<div v-else>
							<el-table-column style="color: red">
								<p>{{scope.row.endTime}}</p>
							</el-table-column>
						</div>
					</div>
				</template>
			</el-table-column>
			<el-table-column prop="isValid" label="是否有效" width="70" sortable>
				<template scope="scope">
					<div>
						<div v-if="scope.row.isValid==='1'">
							<el-table-column style="color: green">
								有效
							</el-table-column>
						</div>
						<div v-else>
							<el-table-column style="color: red">
								无效
							</el-table-column>
						</div>
					</div>
				</template>
			</el-table-column>
			<el-table-column prop="priority" label="排序" sortable/>
			<el-table-column prop="locationType" label="定位类型" sortable>
				<template scope="scope">
					<div>
						<div v-if="scope.row.locationType===1">
							全国
						</div>
						<div v-else-if="scope.row.localtionType===2">
							省市
						</div>
						<div v-else-if="scope.row.localtionType===3">
							坐标定位
						</div>
						<div v-else>

						</div>
					</div>
				</template>
			</el-table-column>
			<el-table-column prop="activityStartTime" label="活跃开始时间" width="170" sortable>
			</el-table-column>
			<el-table-column prop="activityEndTime" label="活跃结束时间" width="170" sortable/>
			<el-table-column prop="registerStartTime" label="注册开始时间" width="170" sortable/>
			<el-table-column prop="registerEndTime" label="注册结束时间" width="170" sortable/>
			<el-table-column prop="insertTime" label="添加时间" width="170" sortable/>
			<el-table-column prop="updateTime" label="更新时间" width="170" sortable/>
			<el-table-column prop="remarks" label="备注" sortable/>
			
			<el-table-column label="操作" width="300" fixed="right">
					<template scope="scope">
						<div style="padding-left:10px"> 
							<el-button
								size="small"
								:type="'info'" @click="handleState(scope.$index, scope.row)"
							>{{scope.row.isValid === 1?'下线':'上线'}} </el-button>
							<el-button size="small" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
							<el-button type="danger" size="small" @click="handleDel(scope.$index, scope.row)">删除</el-button>
						</div>
					</template>
			</el-table-column>
		</el-table>
		<el-col :span="24" class="toolbar">
			<el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :page-size="pageSize" :total="total" style="float:right;">
			</el-pagination>
		</el-col>
		<el-dialog title="广告配置"   v-model="isDialogShow" :close-on-click-modal="false">
			<el-form :model="editForm" label-width="80px"  class="dialog-containt" :rules="addFormRules" ref="editForm" >
				<el-form-item style="margin-left:0px;">
						<el-row type="flex" align="middle">
								<span  ><span  class="warn-label">*</span>广告标题</span>
								<el-col :span="2" style="width: 160px;margin-left:5px;">
									<div style="width:160px;">
										<template>
											<el-input type="text" v-model="editForm.adTitle" placeholder=""></el-input>
										</template>
									</div>
								</el-col>
								
								<el-col :span="2" style="width: 100px;">
									<div style="width:380px;">
									<span style="padding-left:20px" ><span  class="warn-label">*</span>广告位置</span>
										<template>
										<el-select v-model="position" placeholder="请选择" @change="selectPosition">
												<el-option
												v-for="item in adPosition"
												:key="item.position"
												:label="item.positionName"
												:value="item.position">
												</el-option>
											</el-select>
										</template>
									</div>
							</el-col>
						</el-row>
					</el-form-item>

				<div v-show="isShowType==81">

					<el-form-item style="margin-left:0px;" >
						<el-row type="flex" align="left"  >
								<span><span class="warn-label">*</span>图一图片</span>
								<el-col :span="2" style="width: 400px;margin-left:5px;">
									<div style="width:400px;">
										<template>
											<el-input v-model="editForm.onePicUrl"></el-input>
										</template>
									</div>
								</el-col>
						</el-row>
					</el-form-item>
					<el-form-item style="margin-left:0px;" >
						<el-row type="flex" align="left"  >
								<span><span class="warn-label">*</span>图一跳转</span>
								<el-col :span="2" style="width: 400px;margin-left:5px;">
									<div style="width:400px;">
										<template>
											<el-input v-model="editForm.oneJumpUrl"></el-input>
										</template>
									</div>
								</el-col>
						</el-row>
					</el-form-item>
				

					<el-form-item style="margin-left:0px;" >
						<el-row type="flex" align="left"  >
								<span>图二图片</span>
								<el-col :span="2" style="width: 400px;margin-left:5px;">
									<div style="width:400px;">
										<template>
											<el-input v-model="editForm.twoPicUrl"></el-input>
										</template>
									</div>
								</el-col>
						</el-row>
					</el-form-item>

				
					<el-form-item style="margin-left:0px;" >
						<el-row type="flex" align="left"  >
								<span>图二跳转</span>
								<el-col :span="2" style="width: 400px;margin-left:5px;">
									<div style="width:400px;">
										<template>
											<el-input v-model="editForm.twoJumpUrl"></el-input>
										</template>
									</div>
								</el-col>
						</el-row>
					</el-form-item>

					<el-form-item style="margin-left:0px;" >
						<el-row type="flex" align="left"  >
								<span>图三图片</span>
								<el-col :span="2" style="width: 400px;margin-left:5px;">
									<div style="width:400px;">
										<template>
											<el-input v-model="editForm.threePicUrl"></el-input>
										</template>
									</div>
								</el-col>
						</el-row>
					</el-form-item>
					<el-form-item style="margin-left:0px;" >
						<el-row type="flex" align="left"  >
								<span>图三跳转</span>
								<el-col :span="2" style="width: 400px;margin-left:5px;">
									<div style="width:400px;">
										<template>
											<el-input v-model="editForm.threeJumpUrl"></el-input>
										</template>
									</div>
								</el-col>
						</el-row>
					</el-form-item>
				</div>

				<div v-show="isShowType==82">

					<el-form-item style="margin-left:0px;" >
						<el-row type="flex" align="left"  >
								<span><span class="warn-label">*</span>图片URL</span>
								<el-col :span="2" style="width: 400px;margin-left:5px;">
									<div style="width:400px;">
										<template>
											<el-input v-model="editForm.activityIconUrl"></el-input>
										</template>
									</div>
								</el-col>
						</el-row>
					</el-form-item>

					<el-form-item style="margin-left:0px;" >
						<el-row type="flex" align="left"  >
								<span><span class="warn-label">*</span>在线跳转</span>
								<el-col :span="2" style="width: 400px;margin-left:5px;">
									<div style="width:400px;">
										<template>
											<el-input v-model="editForm.activityUrlOnLine"></el-input>
										</template>
									</div>
								</el-col>
						</el-row>
					</el-form-item>
					<el-form-item style="margin-left:0px;" >
						<el-row type="flex" align="left"  >
								<span><span class="warn-label">*</span>离线跳转</span>
								<el-col :span="2" style="width: 400px;margin-left:5px;">
									<div style="width:400px;">
										<template>
											<el-input v-model="editForm.activityUrlOffLine"></el-input>
										</template>
									</div>
								</el-col>
						</el-row>
					</el-form-item>

				<el-form-item style="margin-left:0px;" >
						<el-row type="flex" align="left"  >
								<span><span class="warn-label">*</span>触发方式</span>
								<el-col :span="2" style="width: 400px;margin-left:5px;">
									<div style="width:400px;">
										<el-select v-model="chufaMethod" placeholder="请选择" @change="selectShowType">
												<el-option
												v-for="item in chufaMethodType"
												:key="item.chufaMethod"
												:label="item.chufaMethodName"
												:value="item.chufaMethod">
												</el-option>
											</el-select>
									</div>
								</el-col>
								<span  v-show="isNumber==1">指定周期（天）打开</span>
							<el-col :span="2" style="width: 80px;margin-left:25px;" v-show="isNumber==1">
								<div style="width:160px;">
									<template>
										<el-input  v-model="editForm.day"></el-input>
									</template>
								</div>
							</el-col>
							<span v-show="isDay==1">活动显示次数</span>
								<el-col :span="2" style="width: 80px;margin-left:5px;" v-show="isDay==1">
									<div style="width:160px;">
										<template>
											<el-input  v-model="editForm.number"></el-input>
										</template>
								</div>
							</el-col>
						</el-row>
					</el-form-item>
					<el-form-item style="margin-left:0px;">
						<span><span class="warn-label">*</span>是否显示</span>
						<template>
							<el-radio v-model="editForm.isValid" label="1">显示</el-radio>
							<el-radio v-model="editForm.isValid" label="0">不显示</el-radio>
						</template>
					</el-form-item>
				</div>
				<div v-show="isShowType==3">
					<el-form-item style="margin-left:0px;" >
						<el-row type="flex" align="left"  >
								<span><span class="warn-label">*</span>图片URL</span>
								<el-col :span="2" style="width: 400px;margin-left:5px;">
									<div style="width:400px;">
										<template>
											<el-input v-model="editForm.imageUrl"></el-input>
										</template>
									</div>
								</el-col>
						</el-row>
					</el-form-item>

					<el-form-item style="margin-left:0px;">
						<el-row type="flex" align="middle"  >
								<span><span class="warn-label">*</span>跳转URL</span>
								<el-col :span="2" style="width:400px;margin-left:5px;">
									<div style="width:400px;">
										<template>
											<el-input v-model="editForm.jumpUrl"></el-input>
										</template>
									</div>
								</el-col>
						</el-row>
					</el-form-item>

					<el-form-item style="margin-left:0px;">
						<span><span class="warn-label">*</span>是否显示</span>
						<template>
							<el-radio v-model="editForm.isValid" label="1">显示</el-radio>
							<el-radio v-model="editForm.isValid" label="0">不显示</el-radio>
						</template>
					</el-form-item>
				</div>
				
				<el-form-item style="margin-left:0px;">
					<el-row type="flex" align="middle"  >
							<span><span class="warn-label">*</span>开始版本</span>
						    <el-col :span="2" style="width: 180px;margin-left:5px;">
								<div style="width:160px;">
									<template>
										<el-input v-model="editForm.begin"></el-input>
									</template>
								</div>
							</el-col>

							<span><span class="warn-label">*</span>结束版本</span>
						    <el-col :span="2" style="width: 180px;margin-left:5px;">
								<div style="width:160px;">
									<template>
										<el-input v-model="editForm.end"></el-input>
									</template>
								</div>
							</el-col>
					</el-row>
				</el-form-item>


				<el-form-item style="margin-left:0px;">
					<el-row type="flex" align="middle"  >
							<span>定位类型</span>
						    <el-col :span="2" style="width: 180px;margin-left:5px;">
								<div style="width:160px;">
									<template>
										<el-select v-model="localtion" placeholder="请选择">
												<el-option
												v-for="item in localtionType"
												:key="item.localtion"
												:label="item.localtionName"
												:value="item.localtion">
												</el-option>
											</el-select>
									</template>
								</div>
							</el-col>

							<span>推广渠道</span>
						    <el-col :span="2" style="width: 180px;margin-left:5px;">
								<div style="width:160px;">
									<template>
										<el-input v-model="editForm.poChannel"></el-input>
									</template>
								</div>
							</el-col>
					</el-row>
				</el-form-item>


				<el-form-item style="margin-left:0px;">
					<el-row type="flex" align="middle"  >
							<span>包含区域</span>
						    <el-col :span="2" style="width: 180px;margin-left:5px;">
								<div style="width:160px;">
									<template>
										<el-input v-model="editForm.include"></el-input>
									</template>
								</div>
							</el-col>

							<span>不包含区域</span>
						    <el-col :span="2" style="width: 180px;margin-left:5px;">
								<div style="width:160px;">
									<template>
										<el-input  v-model="editForm.except"></el-input>
									</template>
								</div>
							</el-col>
					</el-row>
				</el-form-item>

				<el-form-item style="margin-left:0px;">
					<el-row type="flex" align="middle"  >
							<span>友盟ID</span>
						    <el-col :span="2" style="width: 180px;margin-left:5px;">
								<div style="width:160px;">
									<template>
										<el-input v-model="editForm.umengId"></el-input>
									</template>
								</div>
							</el-col>

							<span>轮播时间/秒</span>
						    <el-col :span="2" style="width: 180px;margin-left:5px;">
								<div style="width:160px;">
									<template>
										<el-input  v-model="editForm.showTime"></el-input>
									</template>
								</div>
							</el-col>
					</el-row>
				</el-form-item>

				<el-form-item style="margin-left:0px;">
					<el-row type="flex" align="middle"  >
						<span>订单总数>=</span>
						<el-col :span="2" style="width: 180px;margin-left:5px;">
							<div style="width:160px;">
								<template>
									<el-input v-model="editForm.orderCount"></el-input>
								</template>
							</div>
						</el-col>
						<span>VIP用户</span>
						<el-col :span="2" style="width: 180px;margin-left:5px;">
							<div style="width:160px;">
								<template>
									<el-radio v-model="editForm.vipNow" label="1">是</el-radio>
									<el-radio v-model="editForm.vipNow" label="2">否</el-radio>
								</template>
							</div>
						</el-col>
					</el-row>
				</el-form-item>


				<el-form-item style="margin-left:0px;">
					<el-row type="flex" align="middle"  >
						<span>车辆</span>
						<el-col :span="2" style="width: 180px;margin-left:5px;">
							<div style="width:160px;">
								<template>
									<el-radio v-model="editForm.haveCar" label="1">有车</el-radio>
									<el-radio v-model="editForm.haveCar" label="2">无车</el-radio>
								</template>
							</div>
						</el-col>
						<span>驾照</span>
						<el-col :span="2" style="width: 180px;margin-left:5px;">
							<div style="width:160px;">
								<template>
									<el-radio v-model="editForm.drivinglicense" label="1">有驾照</el-radio>
									<el-radio v-model="editForm.drivinglicense" label="2">无驾照</el-radio>
								</template>
							</div>
						</el-col>
					</el-row>
				</el-form-item>


				<el-form-item style="margin-left:0px;">
					<el-row type="flex" align="middle"  >
						<span>付费记录</span>
						<el-col :span="2" style="width: 180px;margin-left:5px;">
							<div style="width:160px;">
								<template>
									<el-radio v-model="editForm.payed" label="1">有</el-radio>
									<el-radio v-model="editForm.payed" label="2">无</el-radio>
								</template>
							</div>
						</el-col>
						<span>用过违章业务</span>
						<el-col :span="2" style="width: 180px;margin-left:5px;">
							<div style="width:160px;">
								<template>
									<el-radio v-model="editForm.wzed" label="1">有</el-radio>
									<el-radio v-model="editForm.wzed" label="2">没</el-radio>
								</template>
							</div>
						</el-col>
					</el-row>
				</el-form-item>

				<el-form-item style="margin-left:0px;">
					<el-row type="flex" align="middle"  >
						<span>系统</span>
						<el-col :span="2" style="width: 180px;margin-left:5px;">
							<div style="width:160px;">
								<template>
									<el-checkbox-group v-model="checkList">
										<el-checkbox label="Android">安卓</el-checkbox>
										<el-checkbox label="iPhone">Ios</el-checkbox>
									</el-checkbox-group>
								</template>
							</div>
						</el-col>
						<span  v-show="isShowType==3">IOS审核</span>
						<el-col v-show="isShowType==3" :span="2" style="width: 220px;margin-left:5px;">
							<div style="width:160px;">
								<template>
									<el-radio v-model="editForm.iosCheckShowFlag" label="1">显示</el-radio>
									<el-radio v-model="editForm.iosCheckShowFlag" label="0">不显示</el-radio>
								</template>
							</div>
						</el-col>
					</el-row>
				</el-form-item>
				
				<el-form-item >
					<div style="block">
						<span>注册时间</span>
						<el-date-picker
						v-model="editForm.registerStartTime"
						type="date"
						placeholder="选择日期"
						format="yyyy 年 MM 月 dd 日"
						value-format="yyyy-MM-dd">
						</el-date-picker>
						~
						<el-date-picker
						v-model="editForm.registerEndTime"
						type="date"
						placeholder="选择日期"
						format="yyyy 年 MM 月 dd 日"
						value-format="yyyy-MM-dd">
						</el-date-picker>
					</div>
				</el-form-item>

				<el-form-item >
					<div style="block">
					<span>活跃时间</span>
						<el-date-picker
						v-model="editForm.activityStartTime"
						type="date"
						placeholder="选择日期"
						format="yyyy 年 MM 月 dd 日"
						value-format="yyyy-MM-dd">
						</el-date-picker>
						~
						<el-date-picker
						v-model="editForm.activityEndTime"
						type="date"
						placeholder="选择日期"
						format="yyyy 年 MM 月 dd 日"
						value-format="yyyy-MM-dd">
						</el-date-picker>
					</div>
				</el-form-item>

				<el-form-item >
					<template>
						<div style="block">
						<span><span class="warn-label">*</span>开始时间</span>
							<el-date-picker
							v-model="editForm.beginTime"
							type="datetime"
							placeholder="选择日期时间"
						>
							</el-date-picker>
							<span class="warn-label">*</span>结束时间
							<el-date-picker
							v-model="editForm.endTime"
							type="datetime"
							placeholder="选择日期时间"
							align="right"
							>
							</el-date-picker>
						</div>
						
					</template>
				</el-form-item>
				<el-form-item label="备注">
					<el-input type="textarea" v-model="editForm.remarks"></el-input>
				</el-form-item>
				
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click.native="isDialogShow = false">取消</el-button>
				<el-button type="primary" @click.native="editSubmit" :loading="addLoading">确定</el-button>
			</div>
		</el-dialog>

	</section>
</template>

<script>
	import util from '../../common/js/util'
	import {
		getAdList,
		addAdvertOrUpdate,
		getPositionList,
		deletePosition,
		changeAdState,
	} from '../../api/api';
	export default {
		data() {
			return {
				selectBeginTime:'',
				selectEndTime:'',
				inputAdTitle:'',
				validoptions: [{
					value: '1',
					label: '有效'
					}, {
					value: '0',
					label: '无效'
				}],
				selectValid:'',
				editForm:{
					isValid:'',
					number:'',
					day:'',
					adId:0,
					end:'',
					begin:'',
					poChannel:'',
					include:'',
					except:'',
					orderCount:'',
					vipNow:'',
					haveCar:'',
					drivinglicense:'',
					payed:'',
					wzed:'',
					registerStartTime:'',
					registerEndTime:'',
					activityStartTime:'',
					activityEndTime:'',
					remarks:'',
					isShowType:'',
					title:'',
					showTime:'',
					umengId:'',
					iosCheckShowFlag:'',
					activityPosition:'',
					position:'',
					insertTime:'',
					updateTime:'',
					beginTime:'',
					endTime:''
				},
				selectPositionCode:'',
				localtion:'',
				checkList: [],
				calculateTime:'',
				value1: '',
				tagsList: [],
				total: 0,
				page: 1,
				pageSize: 20,
				listLoading: false,
				sels: [], //列表选中列
				editFormVisible: false, //编辑界面是否显示
				isDialogShow: false,
				position:'',
				adPosition:[],
				addFormVisible: false, //新增界面是否显示
				addLoading: false,
				pushFormVisible:false,
				isShowType:0,
				//新增界面数据
				isNumber:'',
				isDay:'',
				adList:[],
				localtion:'',
				localtionType:[
					{
						localtion:1,
						localtionName:'全国',
					},
					{
						localtion:2,
						localtionName:'省市',
					}
				],
				showType:'',
				chufaMethod:0,
				chufaMethodType:[
					{
						chufaMethod:0,
						chufaMethodName:'每次打开',
					},
					{
						chufaMethod:1,
						chufaMethodName:'按指定次数打开',
					},
					{
						chufaMethod:2,
						chufaMethodName:'指定周期打开（天）',
					}
				],
                addFormRules: {
                    adTitle: [
                        { required: true, message: '请输入广告标题', trigger: 'blur' }
                    ],
                    adPosition:[
                        { required: true, message: '请选择广告位', trigger: 'blur' }
                    ],
                    beginTime: [
                        { required: true, message: '开始时间必填', trigger: 'blur' }
                    ],
                    endTime:[
                        { required: true, message: '结束时间必填', trigger: 'blur' }
                    ]
                },

			}
		},
		methods: {
			selectQueryPosition(val){
			},
			
			handleCurrentChange(val) {
				this.page = val;
				this.getList();
			},
			handlePush(index, row){
				this.pushFormVisible = true;
				this.calculateTime = ''
				this.pushForm = Object.assign({}, row);
				this.checkList=this.pushForm.system.split(",")
			},
			selectPosition(val){
				console.log(this.isShowType)
				var that = this;
				this.adPosition.forEach(function(item){
					if (item&&item.position==val) {
						that.isShowType = item.type
						console.log("item",item)
					}
				});
			},

			selectShowType(val){
				console.log('this.isShowType:'+val)
				if(val==1){
					this.isDay = 1
					this.isNumber = 0	
				}else if(val==2){
					this.isNumber = 1
					this.isDay = 0
				}else{
					this.isDay = 0
					this.isNumber = 0
				}
				console.log('isDay',this.isDay)
			},
			//获取用户列表
			getList() {
				console.log('getList:'+this.selectPositionCode)
				
				let params = {
					limit:this.pageSize,
					page:this.page,
					inputName:JSON.stringify({
						selectPositionCode:this.selectPositionCode,
						selectEndTime:this.selectEndTime,
						selectBeginTime:this.selectBeginTime,
						selectValid:this.selectValid,
						inputAdTitle:this.inputAdTitle
					})
				}
				this.listLoading = true;
				getAdList(params).then((res) => {
					let result = res.data
					if (result.code == "1000") {
						this.total = res.data.data.total
						console.log(res.data.data.cxyAdvertConfigs)
						this.tagsList = res.data.data.cxyAdvertConfigs.map(item => {
							return Object.assign({}, item, {
								activityEndTime:util.formatDate.format(new Date(item.activityEndTime), 'yyyy-MM-dd hh:mm:ss'),
								activityStartTime:util.formatDate.format(new Date(item.activityStartTime), 'yyyy-MM-dd hh:mm:ss'),
								registerEndTime:util.formatDate.format(new Date(item.registerEndTime), 'yyyy-MM-dd hh:mm:ss'),
								registerStartTime:util.formatDate.format(new Date(item.registerStartTime), 'yyyy-MM-dd hh:mm:ss'),
								endTime:util.formatDate.format(new Date(item.endTime), 'yyyy-MM-dd hh:mm:ss'),
								beginTime:util.formatDate.format(new Date(item.beginTime), 'yyyy-MM-dd hh:mm:ss'),
								insertTime: util.formatDate.format(new Date(item.insertTime), 'yyyy-MM-dd hh:mm:ss'),
								updateTime: util.formatDate.format(new Date(item.updateTime), 'yyyy-MM-dd hh:mm:ss'),
							})
						});
					}
					this.listLoading = false;
				});
				getPositionList().then((res) => {
					let result = res.data
					if (result.code == "1000") {
						this.adPosition = res.data.data.adPosition;
						
					}
				});
			},
			//删除
			handleDel: function(index, row) {
				console.log('handleDel')

				this.$confirm('确认删除该记录吗?', '提示', {}).then(() => {
					this.listLoading = true;
					let params = {
						adId:row.adId
					}
				console.log('handleDel',params)
				deletePosition(params).then((res) => {
						let result = res.data
						console.log('handleDel res',res)
						if (result.code == "1000") {
							this.$message({
								message: '删除成功',
								type: 'success'
							});
							this.getList()
						}else{
							this.$message({
								message: '删除失败',
								type: 'warning'
							});
						}
						this.listLoading = false;
					});
				});
			},
			handleState:function(index, row){
				if(row.isValid=='1'){
					row.isValid = '0'
				}else{
					row.isValid= '1'
				}
				let params = {
					isValid:row.isValid,
					adId:row.adId
				}
				changeAdState(params).then((res) => {
						this.editLoading = false;
						this.$message({
							message: '修改成功',
							type: 'success'
						});
						this.isDialogShow = false;
						this.getList();

					});
			},
			//显示编辑界面
			handleEdit: function(index, row) {
				this.isDialogShow = true;
				console.log('row',row)
				console.log(JSON.parse(row.requirement))
				this.editForm.adId = row.adId
				this.isShowType = row.isShowType
				this.position = row.positionCode
				this.editForm.adTitle = row.adTitle
				this.editForm.imageUrl = row.adJsonImageUrl
				this.editForm.jumpUrl = row.jumpUrl
				this.editForm.showTime = row.showTime
				this.editForm.begin = row.begin
				this.editForm.umengId = row.umengId
				this.editForm.end = row.end
				this.editForm.include = row.include
				this.editForm.except = row.except
				this.editForm.poChannel = row.poChannel
				this.editForm.isValid = row.isValid
				if(row.orderCount){
					this.editForm.orderCount = row.orderCount+""
				}
				this.editForm.vipNow = row.vipNow+""
				this.editForm.haveCar = row.haveCar+""
				this.editForm.drivinglicense = row.drivinglicense +""
				this.editForm.payed = row.payed +""
				this.editForm.iosCheckShowFlag = row.iosCheckShowFlag+""
				console.log('this.editForm.chufaMethod',this.chufaMethod)
				this.editForm.priority=row.priority
				if(row.registerStartTime){
					this.editForm.registerStartTime = row.registerStartTime
				}
				if(row.registerEndTime){
					this.editForm.registerEndTime = row.registerEndTime
				}

				if(row.activityStartTime){
					this.editForm.activityStartTime = row.activityStartTime
				}

				if(row.activityEndTime){
					this.editForm.activityEndTime = row.activityEndTime
				}
				
				this.editForm.remarks = row.remarks
				this.editForm.day = row.day
				this.editForm.number = row.number
				this.localtion = row.locationType
				if(row.phoneOS){
					this.checkList = row.phoneOS.split(",")
				}
				this.editForm.activityPosition =  row.positionCode
				this.editForm.activityIconUrl = row.activityIconUrl
				this.editForm.activityUrlOffLine = row.activityUrlOffLine
				this.editForm.activityUrlOnLine = row.activityUrlOnLine
				this.editForm.wzed = row.wzed
				this.editForm.onePicUrl = row.onePicUrl
				this.editForm.oneJumpUrl = row.oneJumpUrl
				this.editForm.twoPicUrl = row.twoPicUrl
				this.editForm.twoJumpUrl = row.twoJumpUrl
				this.editForm.threeJumpUrl = row.threeJumpUrl
				this.editForm.threePicUrl = row.threePicUrl

				console.log('row.registerStartTime', row.registerStartTime)
				if(row.beginTime){
					this.editForm.beginTime = row.beginTime
				}
				if(row.endTime){
					this.editForm.endTime = row.endTime
				}

			},
			//显示新增界面
			handleAdd: function() {
				this.editForm =  {};
				this.isDialogShow = true;
			},
			//编辑
			editSubmit: function() {
				console.log("--------this.iosCheckShowFlag ---------"+this.editForm.iosCheckShowFlag )
				console.log(this.isShowType)
				console.log(this.editForm)
				var phoneOS = "";
				var str = ""
				if(this.checkList){
					this.checkList.forEach(function(element) {
										str += element+",";
									}, this);
								phoneOS = phoneOS.substring(0,phoneOS.length-1);
				}
				var params ={
							adId:this.editForm.adId,
							adTitle:this.editForm.adTitle,
							positionCode:this.position,
							end:this.editForm.end,
							begin:this.editForm.begin,
							poChannel:this.editForm.poChannel,
							include:this.editForm.include,
							except:this.editForm.except,
							orderCount:this.editForm.orderCount,
							vipNow:this.editForm.vipNow,
							haveCar:this.editForm.haveCar,
							drivinglicense:this.editForm.drivinglicense,
							payed:this.editForm.payed,
							wzed:this.editForm.wzed,
							registerStartTime:this.editForm.registerStartTime,
							registerEndTime:this.editForm.registerEndTime,
							activityStartTime:this.editForm.activityStartTime,
							activityEndTime:this.editForm.activityEndTime,
							remarks:this.editForm.remarks,
							isShowType:this.isShowType,
							showTime:this.editForm.showTime,
							umengId:this.editForm.umengId,
							phoneOS:phoneOS,
							iosCheckShowFlag:this.editForm.iosCheckShowFlag,
							priority:this.editForm.priority,
							activityIconUrl:this.editForm.activityIconUrl,
							activityUrlOffLine:this.editForm.activityUrlOffLine,
				 			activityUrlOnLine:this.editForm.activityUrlOnLine,
							day:this.editForm.day,
							number:this.editForm.number,
							isShow:this.editForm.isShow,
							showType:this.chufaMethod,
							onePicUrl:this.editForm.onePicUrl,
							oneJumpUrl:this.editForm.oneJumpUrl,
							twoPicUrl:this.editForm.twoPicUrl,
							twoJumpUrl:this.editForm.twoJumpUrl,
							threePicUrl:this.editForm.threePicUrl,
							threeJumpUrl:this.editForm.threeJumpUrl,
							endTime:this.editForm.endTime,
							beginTime:this.editForm.beginTime,
							isValid:this.editForm.isValid,
							locationType:this.localtion
						}
				switch (this.isShowType) {
					case 0:
						
						break;
					case 1:
					
						break;
					case 2:
						break;
					case 3:
						Object.assign(params, {
								jumpUrl:this.editForm.jumpUrl,
								imageUrl:this.editForm.jumpUrl,
                            })
						break;
				}
			
				this.$confirm('确认提交吗？', '提示', {}).then(() => {
					
					addAdvertOrUpdate(params).then((res) => {
						this.editLoading = false;
						this.$message({
							message: '提交成功',
							type: 'success'
						});
						this.isDialogShow = false;
						this.getList();

					});
				});
			},
			selsChange: function(sels) {
				this.sels = sels;
			},
			compareNow: function (date) {
                var curTime = new Date();
                var newDate = new Date(date);
                //console.log("======当前时间：==============="+curTime+"==时间===="+newDate+"==== 比较结果：===")
                if(newDate>=curTime){
                    return true;
                }else{
                    return false;
                }
            }
		},

		mounted() {
			this.getList();
		}
	}
</script>

<style scoped>
.dialog-containt{
	margin-left:-40px;
}
.warn-label{
	color:red;
}
</style>